﻿@page "/Archive/Product/Index"
@page "/Archive/Product/Index/{Token}"
@using iTeamyou.LTS.UI.Models;
@using iTeamyou.LTS.UI.Shared.Components;

<h5 style="margin-top: 1.5rem;">管理商品库</h5>
<div style="margin-top: 2rem;">
    <Button Text="新建商品" OnClick="@Add" IsDisabled="IsUnauth" />
    <Button Text="编辑" OnClick="@EditBtn" IsDisabled="@(SelectedProducts.Count != 1)" />
    <PopConfirmButton Color="Color.Danger" IsDisabled="@(SelectedProducts.Count == 0)" OnConfirm="(() => Delete(SelectedProducts))" ConfirmIcon="fa-solid fa-triangle-exclamation text-danger" ConfirmButtonColor="Color.Danger" Content="确定删除选中的记录吗？">删除</PopConfirmButton>
    <Button Text="导出" OnClick="@Export" IsDisabled="IsUnauth" />
</div>
@*
*@
<Table style="margin-top: 1rem;" TItem="Core.Models.Product"
       IsPagination="true" PageItemsSource="@PageItemsSource" IsStriped="true" ShowLineNo="true"
       CustomerSearchModel="@ProductSearchModel" SearchMode="SearchMode.Top" ShowSearchText="true" ShowSearch="true" 
       OnDoubleClickRowCallback="@Edit"
       SelectedRows="@SelectedProducts" SelectedRowsChanged="@SelectChanged" IsMultipleSelect="true"
       ShowSkeleton="true" ShowResetButton="true" ShowEmpty="true"
       OnQueryAsync="@OnQueryAsync" IsAutoRefresh="@IsAutoRefresh" AutoRefreshInterval="2000">
    <TableColumns>
        <TableColumn @bind-Field="@context.PId" Width="80" Readonly="true" />
        <TableColumn @bind-Field="@context.UPC" Width="80" />
        <TableColumn @bind-Field="@context.Name" Width="200" Readonly="true" />
        <TableColumn @bind-Field="@context.Specification" Width="100" Readonly="true" />
        <TableColumn @bind-Field="@context.Brand" Width="40" Readonly="true" />
        <TableColumn @bind-Field="@context.SectionId" Width="80" Readonly="true" Text="商品分类" >
            <Template Context="value">
                <Tag Color="Color.Primary">@ProductService.GetProductDepartment(value.Value).Description</Tag>
            </Template>
        </TableColumn>
        <TableColumn @bind-Field="@context.OriginPlace" Width="40" Readonly="true" />
        <TableColumn @bind-Field="@context.LastModifiedOn" Width="80" Sortable="true" Readonly="true" />
        <TableColumn @bind-Field="@context.LicenseNum" Width="80" Text="证照数">
            <Template Context="value">
                @if (value.Value == null || value.Value == 0)
                {
                    <Tag Color="Color.Dark">共 0 个证照</Tag>
                }
                else
                {
                    <Tag Color="Color.Primary">共 @value.Value 个证照</Tag>
                }
            </Template>
        </TableColumn>
    </TableColumns>
    <CustomerSearchTemplate>
        @if (context is ProductSearchModel model)
        {
            <ProductSearch @bind-Value="@model" />
        }
    </CustomerSearchTemplate>
</Table>